﻿@using EasyCourse.Model;
@{
    Layout = null;
    CommonPageInfo pageInfo = ViewData[CommonViewDataKey.CommonPageInfo] as CommonPageInfo;
    var courseOtherInfoTypeDic = CourseOtherInfoManage.Instance.CourseOtherInfoTypeDic;
    int? typeCode = null;
    if (!string.IsNullOrEmpty(Convert.ToString(ViewData["TypeCode"])))
    {
        typeCode = ViewData["TypeCode"] as int?;
    }
}
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>精品课程管理</title>
    @Html.Partial("~/Views/Share/PublicHeader.cshtml")
</head>
<body>
    @Html.Partial("~/Views/Share/PublicTopNav4Teacher.cshtml")
    <div class="container">
        <div class="row">
            <h1 class="topTitle-h1">
                @pageInfo.CourseName<br>
                <small>广州中医药大学康复治疗微课程网络学习平台</small>
            </h1>
        </div>
    </div>
    @*导航菜单*@
    @Html.Partial("~/Views/Share/PublicTeacherNaviMenu.cshtml", 0)
    <div class="container">
        <div class="row">
            @Html.Partial("~/Views/Share/PublicCourseOtherInfoMenu.cshtml", this.ViewData)
            <div class="col-xs-10">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">
                            <ol class="breadcrumb">
                                <li>精品课程管理</li>
                                <li>@courseOtherInfoTypeDic[typeCode.Value]</li>
                                <li class="active">内容管理</li>
                            </ol>
                        </h3>
                    </div>
                    <div class="panel-body">
                        <ul id="myTab" class="nav nav-tabs">
                            <li class="active"><a href="#home" data-toggle="tab">简单类型</a></li>
                            <li><a href="#ios" data-toggle="tab">复杂类型</a></li>
                        </ul>
                        <div id="myTabContent" class="tab-content mt15">
                            <div class="tab-pane fade in active" id="home">
                                <div class="row">
                                    <form id="valid_form1" action="@Url.Action("CourseOtherInfoContentAdd", "CourseOtherInfo")" method="post" class="form-horizontal" role="form">
                                        @Html.Hidden("PId")
                                        @Html.Hidden("CourseId")
                                        @Html.Hidden("TypeCode")
                                        @Html.Hidden("IsMenu", false)
                                        @Html.Hidden("IsSimpleType", true)
                                        <div class="form-group">
                                            <label class="col-xs-2 control-label" for="Title">名称:</label>
                                            <div class="col-xs-4">
                                                <input type="text" name="Title" class="form-control input-md" id="Title">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label col-xs-2" for="StatusCode">是否发布:</label>
                                            <div class="col-xs-2">
                                                <select class="form-control input-sm" name="StatusCode">
                                                    <option value="4" selected>是</option>
                                                    <option value="0">否</option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label col-xs-2">已选文件:</label>
                                            <div class="col-xs-4">
                                                <input type="hidden" name="CourseContent" />
                                                <input name="fileName" id="JfileName" class="form-control mb10" readonly="readonly" />
                                                <p class="mb10"><em class="red ">课程文件只能上传PDF文件</em>                                 </p>
                                                <input id="file_upload" name="file_upload" type="file" class="form-control input-sm">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-xs-offset-2 col-xs-10">
                                                <button type="button" onclick="autoSubmit('valid_form1')" class="btn btn-success btn-md"><span class="glyphicon glyphicon-ok"></span>保存 </button>
                                                <button type="button" onclick="history.go(-1)" class="btn btn-success btn-md"><span class="glyphicon glyphicon-arrow-left"></span>返回</button>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                            <div class="tab-pane fade" id="ios">
                                <div class="row">
                                    <form id="valid_form2" action="@Url.Action("CourseOtherInfoContentAdd", "CourseOtherInfo")" method="post" class="form-horizontal" role="form">
                                        @Html.Hidden("PId")
                                        @Html.Hidden("CourseId")
                                        @Html.Hidden("TypeCode")
                                        @Html.Hidden("IsMenu", false)
                                        @Html.Hidden("IsSimpleType", false)
                                        <div class="form-group">
                                            <label class="col-xs-2 control-label" for="Title">名称:</label>
                                            <div class="col-xs-6">
                                                <input type="text" name="Title" class="form-control input-md">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label col-xs-2">是否发布:</label>
                                            <div class="col-xs-2">
                                                <select class="form-control input-sm" name="StatusCode">
                                                    <option value="4" selected>是</option>
                                                    <option value="0">否</option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-xs-offset-2 col-xs-10">
                                                <textarea id="CourseContent" name="CourseContent" class="form-control" style="width: 100%; height: 600px;"></textarea>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-xs-offset-2 col-xs-10">
                                                <button type="button" onclick="autoSubmit('valid_form2')" class="btn btn-success btn-md"><span class="glyphicon glyphicon-ok"></span>保存 </button>
                                                <button type="button" onclick="history.go(-1)" class="btn btn-success btn-md"><span class="glyphicon glyphicon-arrow-left"></span>返回</button>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    @Html.Partial("~/Views/Share/PublicFooter.cshtml")
    @Html.Partial("~/Views/Share/PublicCommonJs.cshtml")

    <script src="~/Content/jquery.form.js"></script>
    @*kindeditor.js有自己修改过For Ckplayer*@
    <script src="../Content/kindeditor/kindeditor.js"></script>
    <script src="../Content/kindeditor/lang/zh_CN.js"></script>
    <script src="../Content/kindeditor/plugins/insertVideo/ckplayer/ckplayer.js"></script>
    <script type="text/javascript" src=@Url.Content("~/Content/uploadify/jquery.uploadify.min.js?ver=")@DateTime.Now.Ticks></script>
    <link href="../Css/uploadify.css" rel="stylesheet" />
    <script>
        //上传文件
        var _attachmentUrl = null;
        $("#file_upload").uploadify({
            'queueSizeLimit': 1,
            //fileType代表文件类型的值可能有:   Image 、 OtherFile 、 Temp
            'formData': { 'fileType': 'CourseInfo' },
            'buttonText': '请选择上传文件',
            'swf': '../Content/uploadify/uploadify.swf',
            'uploader': '/Base/UpLoad',
            'onUploadSuccess': function (file, data, response) {
                var json = $.parseJSON(data);
                if (json.result) {
                    _attachmentUrl = json.message; //文件保存的地址
                    $("#JfileName").val(file.name);
                    $("#JfileName").attr("data-fileUrl", _attachmentUrl);
                    $("input[type=hidden][name='CourseContent']").val(_attachmentUrl);
                }
                else {
                    showTips.open(json.message);
                }
            }

        });

        @* $("#courseInfoList li").click(function () {
            var _typeCode = $(this).attr("id");
            window.location.href = "@Url.Action("CourseOtherInfoList", "CourseOtherInfo")?TypeCode=" + _typeCode;
        });*@

        var editor;
        KindEditor.ready(function (K) {
            editor = K.create('#CourseContent', {
                uploadJson: '@Url.Content("~/upload_json.ashx")',
                fileManagerJson: '@Url.Content("~/file_manager_json.ashx")',
                allowFileManager: true
            });
        });





        var t = true;
        function autoSubmit(frmId) {
            var jsonData;

            if (frmId == "valid_form1") {
                var frm1 = $("#valid_form1");
                var PId = frm1.find("#PId").val();
                var CourseId = frm1.find("#CourseId").val();
                var TypeCode = frm1.find("#TypeCode").val();
                var IsMenu = frm1.find("#IsMenu").val();
                var IsSimpleType = frm1.find("#IsSimpleType").val();
                var Title = frm1.find("#Title").val();
                var StatusCode = frm1.find("select[name='StatusCode'] option:selected").val();
                var CourseContent = frm1.find("input[name='CourseContent']").val();
                jsonData = {
                    "PId": PId,
                    "CourseId": CourseId,
                    "TypeCode": TypeCode,
                    "IsMenu": IsMenu,
                    "IsSimpleType": IsSimpleType,
                    "Title": Title,
                    "StatusCode": StatusCode,
                    "CourseContent": CourseContent
                };
            }
            else {
                var frm2 = $("#valid_form2");
                var PId = frm2.find("#PId").val();
                var CourseId = frm2.find("#CourseId").val();
                var TypeCode = frm2.find("#TypeCode").val();
                var IsMenu = frm2.find("#IsMenu").val();
                var IsSimpleType = frm2.find("#IsSimpleType").val();
                var Title = frm2.find("input[name='Title']").val();
                var StatusCode = frm2.find("select[name='StatusCode'] option:selected").val();
                var CourseContent = editor.html();
                jsonData = {
                    "PId": PId,
                    "CourseId": CourseId,
                    "TypeCode": TypeCode,
                    "IsMenu": IsMenu,
                    "IsSimpleType": IsSimpleType,
                    "Title": Title,
                    "StatusCode": StatusCode,
                    "CourseContent": CourseContent
                };
            }

            editor.sync();
            $.easyPost("@Url.Action("CourseOtherInfoContentAdd", "CourseOtherInfo")", jsonData, function (data) {
                if (data.result) {
                    showTips.open("添加成功！");
                    $("#" + frmId)[0].reset();
                    editor.html("");
                } else {
                    showTips.open(data.message)
                }
            }, "json")
        };

    </script>
</body>
</html>
